#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=1010;
int n,head[MAXN],cnt,a[MAXN];
struct edge
{
	int v,next,val;
}e[MAXN<<1];
void addedge(int x,int y,int z)
{
	e[++cnt]=(edge){y,head[x],z};
	head[x]=cnt;
	return;
}
void dfs(int u,int lst)
{
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].v;
		if(v==lst)continue;
		a[v]=a[u]^e[i].val;
		dfs(v,u);
	}
	return;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=read();
	for(int i=1;i<n;++i)
	{
		int x=read(),y=read(),z=read();
		addedge(x,y,z);addedge(y,x,z);
	}
	dfs(1,0);
	printf("%d\n",a[n]);
	return 0;
}
